// view/view.go
package view

import (
	"html/template"
	"net/http"
)

type View struct{}

func (v *View) Show(w http.ResponseWriter, tmpl string, data interface{}) {
	// 使用完整路径，Go 需要指定模板文件夹
	t, err := template.ParseFiles("templates/" + tmpl + ".html")
	if err != nil {
		http.Error(w, "模板加载失败: "+err.Error(), http.StatusInternalServerError)
		return
	}
	// 修正：Execute 而不是 Excute
	err = t.Execute(w, data)
	if err != nil {
		http.Error(w, "模板执行失败: "+err.Error(), http.StatusInternalServerError)
	}
}
